import {getShopData} from '../../api/business';

export default{
	namespaced:true,
	state:{
		shops:[]
	},
	mutations:{
		//设置商铺列表
		["SET_SHOPS"](state,payload){
			console.log(payload.shops);
			state.shops = payload.shops;
		},
		//设置商业分页数据
		["SET_SHOPS_PAGE"](state,payload){
			console.log(payload.shops);
			state.shops.push(...payload.shops);
		},
	},
	actions:{
		//获取首页商铺数据
		getShop(conText,payload){
			 getShopData(payload).then(res=>{
				if(res.code==200){
					conText.commit("SET_SHOPS",{shops:res.data});
				    if(payload.success){
						payload.success(res.pageinfo.pagenum);
					}	
				}
				
				if(payload.complete){
					payload.complete()
				}
			 })
		},
		
		//显示首页分页商家数据
		getShopPage(conText,payload){
			getShopData(payload).then(res=>{
							if(res.code==200){
								conText.commit("SET_SHOPS_PAGE",{shops:res.data});
							}
			})
		}
		
	}
}